var mysqlClient = require('../libs/mysqlClient');

function Service() {
    this.list = function(params, callback) {
        const currentId = params['*session'].id;
        mysqlClient.queryList('select * from t_score where from_user = ? or to_user = ?', [currentId, currentId], callback);
    }
    this.retrieve = function(id, params, callback) {
        mysqlClient.getObject('t_score', { id: id }, callback);
    }
    this.create = function(params, callback) {
        mysqlClient.addObject('t_score', params, callback);
    }
    this.update = function(id, params, callback) {
        mysqlClient.getObject('t_score', { id: id }, function(data) {
            if (data) {
                mysqlClient.updateObject('t_score', params, { id: id }, callback);
            } else {
                callback({ error: '没有数据' });
            }
        });
    }
    this.delete = function(id, params, callback) {
        mysqlClient.deleteObject('t_score', { id: id }, callback);
    }
}
exports.service = Service;